import router from '@/router/index.js'
export default {
  data() {
    return {
      subject_all: [{
          "name": "语文",
          "f": "chinese"
        },
        {
          "name": "数学",
          "f": "mathematics"
        },
        {
          "name": "英语",
          "f": "english"
        },
        {
          "name": "科学",
          "f": "science"
        },
        {
          "name": "物理",
          "f": "physics"
        },
        {
          "name": "化学",
          "f": "chemistry"
        },
        {
          "name": "生物",
          "f": "biology"
        },
        {
          "name": "地理",
          "f": "geography"
        },
        {
          "name": "历史",
          "f": "history"
        },
        {
          "name": "道德与法治",
          "f": "law"
        },
        {
          "name": "体育",
          "f": "sports"
        }
      ]
    }
  },
  onLoad(options) {},

  methods: {

    // 时间戳转换成时间
    timestampToTime (cjsj) {
      var date = new Date(cjsj*1000) //时间戳为10位需*1000，时间戳为13位的话不需乘1000
      var Y = date.getFullYear() + '-'
      var M = (date.getMonth()+1 < 10 ? '0'+(date.getMonth()+1) : date.getMonth()+1) + '-'
      var D = date.getDate() + ' '
      var h = date.getHours() + ':'
      var m = date.getMinutes() + ':'
      var s = date.getSeconds()
      return Y+M+D+h+m+s
    },
    // 路由跳转
    jump(path, parmas, _blank) {
      if (_blank) {
        // 打开新页面
        let routeUrl = router.resolve({
          path: path,
          query: parmas
        });
        window.open(routeUrl.href, '_blank');
      } else {
        router.push({
          path: path,
          query: parmas
        });
      }
    },
    // 小数显示两位 number：显示的位数，默认为2
    decimals(val, number) {
      if (Array.isArray(val)) {
        let valList = val.map((item, index) => {
          return this.dec(item, number);
        })
        return valList;
      } else {
        return this.dec(val, number);
      }
    },
    dec(val, number) {
      let locat = String(val).indexOf(".") + 1; //获取小数点的位置
      if (locat > 0 && val) {
        if (number === undefined) {
          number = 2;
        }
        return Number(val).toFixed(number)
      } else {
        return val
      }
    },
    // 科目字段英文转中文
    matchChinese(property) {
      let r;
      this.subject_all.map((item, index) => {
        if (property == item.f) {
          r = item.name;
        }
      });
      return r;
    },
    // 小数转百分比
    toPercent(point) {
      let str = Number(point * 100).toFixed(1);
      // str+="%";
      return str;
    }
  }


}
